package com.Algorithm.HUAWEI.three20220323;

import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/03/23/15:04
 * @Description:
 * @Target:
 */
public class 学英语 {


    /*
    *
    *
    * 描述
        Jessi初学英语，为了快速读出一串数字，编写程序将数字转换成英文：

        具体规则如下:
        1.在英语读法中三位数字看成一整体，后面再加一个计数单位。从最右边往左数，三位一单位，例如12,345 等
        2.每三位数后记得带上计数单位 分别是thousand, million, billion.
        3.公式：百万以下千以上的数 X thousand X, 10亿以下百万以上的数：X million X thousand X,
        * 10 亿以上的数：X billion X million X thousand X. 每个X分别代表三位数或两位数或一位数。
        4.在英式英语中百位数和十位数之间要加and，美式英语中则会省略，我们这个题目采用加上and，百分位为零的话，这道题目我们省略and

        下面再看几个数字例句：
        22: twenty two
        100:  one hundred
        145:  one hundred and forty five
        1,234:  one thousand two hundred and thirty four
        8,088:  eight thousand (and) eighty eight (注:这个and可加可不加，这个题目我们选择不加)
        486,669:  four hundred and eighty six thousand six hundred and sixty nine
        1,652,510:  one million six hundred and fifty two thousand five hundred and ten

        说明：
        数字为正整数，不考虑小数，转化结果为英文小写；
        保证输入的数据合法
        关键字提示：and，billion，million，thousand，hundred。

        数据范围：1≤n≤2000000


        输入描述：
        输入一个long型整数

        输出描述：
        输出相应的英文写法

        示例1
        输入：
        22
        复制
        输出：
        twenty two
*/


    // ,,表示millions和thousands
    // ,后的第一个数是hundred and

    public static void main(String[] args) throws IOException {
//        Scanner in = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            process(in.readLine());

    /*    for (int i = 1; i < 300; i++) {
            process(i+"");
            System.out.println();
        }*/


    }


    static void process(String ss1){
        StringBuffer stringBuffer = new StringBuffer(ss1);
        stringBuffer.reverse();
        StringBuffer stringBuffer1 = new StringBuffer();
        for (int i = 0; i < stringBuffer.length(); i++) {
            stringBuffer1.append(stringBuffer.charAt(i));

            if (i!=0&&(i+1)%3==0&&i!=stringBuffer.length()-1){
                stringBuffer1.append(",");
            }
        }

        String ss = stringBuffer1.reverse().toString();
        System.out.println(ss);
        int count = 0;   // 记录,
        for (int i = 0; i < ss.length(); i++) {
            if (ss.charAt(i)==','){
                count++;
            }
        }


        if (count==2){
            String[] split = ss.split(",");
            System.out.print(threeNumDeal(split[0]));
            System.out.print(" million ");
            System.out.print(threeNumDeal(split[1]));
            System.out.print(" thousand ");
            System.out.print(threeNumDeal(split[2]));

        }else if (count==1){
            String[] split = ss.split(",");
            System.out.print(threeNumDeal(split[0]));
            System.out.print(" thousand ");
            System.out.print(threeNumDeal(split[1]));
        }else {
            System.out.print(threeNumDeal(ss));
        }

    }


    static String threeNumDeal(String ss){
        boolean flag = false;
        StringBuffer stringBuffer = new StringBuffer();
        if (ss.length()==3){
            if (ss.charAt(0)!='0'&&ss.contains("00")){
                stringBuffer.append(NumToEnString(ss.charAt(0)+""));
                stringBuffer.append(" hundred");
                flag = true;
            }else if (ss.charAt(0)!='0'&&!ss.contains("00")){
               stringBuffer.append(NumToEnString(ss.charAt(0)+""));
               stringBuffer.append(" hundred and");
               flag = true;
            }

            if (flag==true&&ss.charAt(1)!='0'){
               stringBuffer.append(" "+NumToEnString((ss.charAt(1)-'0')*10+(ss.charAt(2)-'0')+""));
            }else if (flag==true&&ss.charAt(1)=='0'){
               stringBuffer.append(" "+NumToEnString(ss.charAt(2)+""));
            }else  if (flag==false&&ss.charAt(1)!='0'){
                stringBuffer.append(NumToEnString((ss.charAt(1)-'0')*10+(ss.charAt(2)-'0')+""));
            }else if (flag==false&&ss.charAt(1)=='0'){
                stringBuffer.append(NumToEnString(ss.charAt(2)+""));
            }

        }else if (ss.length()==2){
           stringBuffer.append(NumToEnString((ss.charAt(0)-'0')*10+(ss.charAt(1)-'0')+""));
        }else if (ss.length()==1){ stringBuffer.append(NumToEnString(ss.charAt(0)+""));}
        return stringBuffer.toString();
    }
    // 目前处理1-99
    static String NumToEnString(String ss){
        Integer integer = Integer.valueOf(ss);
        StringBuffer recordStringBuffer = new StringBuffer();


        if (integer<10){
        switch (integer){
            case 1:recordStringBuffer.append("one");break;
            case 2:recordStringBuffer.append("two");break;
            case 3:recordStringBuffer.append("three");break;
            case 4:recordStringBuffer.append("four");break;
            case 5:recordStringBuffer.append("five");break;
            case 6:recordStringBuffer.append("six");break;
            case 7:recordStringBuffer.append("seven");break;
            case 8:recordStringBuffer.append("eight");break;
            case 9:recordStringBuffer.append("nine");break;
        }

        }else if (integer>=20){

            Integer i1 = 0;
            Integer i2 = 0;
            i1 = integer%10;  // 个位数字
            i2 = integer/10;  // 十位数字

            switch (i2){
                case 2:recordStringBuffer.append("twenty");break;
                case 3:recordStringBuffer.append("thirty");break;
                case 4:recordStringBuffer.append("forty");break;
                case 5:recordStringBuffer.append("fifty");break;
                case 6:recordStringBuffer.append("sixty");break;
                case 7:recordStringBuffer.append("seventy");break;
                case 8:recordStringBuffer.append("eighty");break;
                case 9:recordStringBuffer.append("ninety");break;
            }

            switch (i1){
                case 1:recordStringBuffer.append(" one");break;
                case 2:recordStringBuffer.append(" two");break;
                case 3:recordStringBuffer.append(" three");break;
                case 4:recordStringBuffer.append(" four");break;
                case 5:recordStringBuffer.append(" five");break;
                case 6:recordStringBuffer.append(" six");break;
                case 7:recordStringBuffer.append(" seven");break;
                case 8:recordStringBuffer.append(" eight");break;
                case 9:recordStringBuffer.append(" nine");break;
            }


        }else {  // 10-19
            switch (integer){
                case 10:recordStringBuffer.append("ten");break;
                case 11:recordStringBuffer.append("eleven");break;
                case 12:recordStringBuffer.append("twelve");break;
                case 13:recordStringBuffer.append("thirteen");break;
                case 14:recordStringBuffer.append("fourteen");break;
                case 15:recordStringBuffer.append("fifteen");break;
                case 16:recordStringBuffer.append("sixteen");break;
                case 17:recordStringBuffer.append("seventeen");break;
                case 18:recordStringBuffer.append("eighteen");break;
                case 19:recordStringBuffer.append("nineteen");break;
            }
        }


        return recordStringBuffer.toString();

    }
}
